function onPacientesLoad(){
    initPacienteDetailUI();

    pacienteModel.removeIdChangedListener(pacienteEvaluacionSelect, evaluacionesModel);
    pacienteModel.removeIdChangedListener(pacienteRiesgoSelect, riesgosModel);
    pacienteModel.removeIdChangedListener(pacienteEvalClinicaSelect, evalClinicasModel);
    pacienteModel.removeIdChangedListener(pacienteFormulaDesarrolladaSelect, formulasDesarrolladasModel);
    pacienteModel.removeIdChangedListener(pacienteToleranciaSelect, toleranciaModel);
    pacienteModel.removeIdChangedListener(pacienteAlimentacionHabitualSelect, alimentacionHabitualModel);
    
    pacienteModel.addIdChangedListener(pacienteDetailSelect, pacienteDetailUI);
}

function initPacienteTableUI(){      
   
      pacienteTableUI = new TableUI(
        "pacientes_table",
        "pacientes_pager",
        "Pacientes", 
        325
      );

      pacienteTableUI.setModel(pacienteModel);

      pacienteTableUI.addColumn("Paciente", "id", "Id", "id", 50);
      pacienteTableUI.addColumn("Paciente", "nombre", "Nombre", "nombre", 125);
      pacienteTableUI.addColumn("Paciente", "apellido", "Apellido", "apellido", 125);

      pacienteTableUI.initTable();


      pacienteTableUI.setPagesControl(document.getElementById('page_pac'));
      //pacienteTableUI.setRegsByPageControl(document.getElementById('limit_pac'));
}

function initPacienteDetailUI(){
    pacienteDetailUI = new DetailUI("Paciente");

    pacienteDetailUI.setModel(pacienteModel);
    pacienteDetailUI.setTitleContainer(document.getElementById("detail_title"));
    pacienteDetailUI.setMessageContainer(document.getElementById("errorMessage"));

    pacienteDetailUI.setAddButton(document.getElementById("add_pac"));
    pacienteDetailUI.setEditButton(document.getElementById("edit_pac"));
    pacienteDetailUI.setDelButton(document.getElementById("del_pac"));

    pacienteDetailUI.setOkButton(document.getElementById("sbtguardar"));

    pacienteDetailUI.addField(document.getElementById("nombre"), "Paciente", "nombre", "string", 1, false);
    pacienteDetailUI.addField(document.getElementById("apellido"), "Paciente", "apellido", "string", 1, false);
    pacienteDetailUI.addField(document.getElementById("sexo"), "Paciente", "sexo", "string", 1, false);
    pacienteDetailUI.addField(document.getElementById("fecha_nacimiento"), "Paciente", "fecha_nacimiento", "date", 10, false);
    pacienteDetailUI.addField(document.getElementById("direccion"), "Paciente", "direccion", "string", 4, true);
    pacienteDetailUI.addField(document.getElementById("telefono"), "Paciente", "telefono", "string", 4, true);
    pacienteDetailUI.addField(document.getElementById("mail"), "Paciente", "mail", "email", 4, true);
    pacienteDetailUI.addField(document.getElementById("profesion"), "Paciente", "profesion", "string", 3, false);
    pacienteDetailUI.addField(document.getElementById("derivacion"), "Paciente", "derivacion", "string", 3, false);

    if(pacienteModel.idColumn.value == undefined ||
       pacienteModel.idColumn.value == "" ||
       pacienteModel.idColumn.value == 0){
        pacienteDetailUI.add();
    }else{
        pacienteDetailUI.edit();
    }
}

function pacienteDetailSelect(id, context){
    context.edit();
}

